
<div class="templatemo-content-wrapper">
	<div class="templatemo-content">
		<ul class="nav nav-tabs mytabs">
		  <li class="active"><a href="#">编辑商品</a></li>
		  <li ><a href="<?php echo site_url('kickback/index/id/'.$kickback['userid'])?>">商品列表</a></li>
		</ul>
		<div class="row">
			<div class="col-md-12">
				<div class="table-responsive">
					 
					<form role="form" id="templatemo-preferences-form"
						onsubmit="return false;">
						 <div class="row">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">商品名称</label> <input
									type="text" class="form-control" id="name" value="<?=$kickback['name'].'-'.$kickback['productid']?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">原价</label> <input
									type="text" class="form-control" id="price" value="<?=$kickback['price']?>">
							</div>
						</div>
						<div class="row">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">涨价比例</label> <input
									type="text" class="form-control" id="rate" value="<?=$kickback['rate']?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">设置价</label> <input
									type="text" class="form-control" id="newprice" value="<?=$kickback['newprice']?>">
							</div>
						</div>
						<div class="row templatemo-form-buttons">
							<div class="col-md-12">
								<input type="hidden" id="id" value="<?=$kickback['id']?>" />
								<input type="hidden" class="form-control" id="userid" value="<?=$kickback['userid']?>">
								<button type="submit" class="btn btn-primary" id="submit_btn">修改</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function() {
		$("#name").autocomplete({
			minLength:1,
			source:function(request,response){
				/*var term = request.term;
				if ( term in cache ) {
         			 response( cache[ term ] );
         			 return;
       			 }*/
       			 $.ajax({
                    url:'<?php echo site_url('product/getShowProduct')?>',
                    type : "post",
                    dataType: "json",
                    data:{
                        name: request.term
                    },
                    success: function( data ) {
                        //cache[ term ] = data;
                        response($.map(data, function(item) {
    		            return {
    		                 label: item.name+'-'+item.description,
    		                 value: item.name+ '-' + item.id
    		             }
    		         }));
                    }
                });
			}
		});
		$("#submit_btn").click(function() {
			var id = $("#id").val();
			var name = $("#name").val();
			var userid = $("#userid").val();
			var rate = $("#rate").val();
			var newprice = $("#newprice").val();
			$.ajax({
				url : '<?php echo site_url('kickback/save')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'name' : name,
					'userid' : userid,
					'rate' : rate,
					'newprice' : newprice
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
					}else{
						alert(data.msg);
					}
				}
			});
		});
	}); 
</script>